﻿@model LotteryVoteMVC.Models.ShadowAuthModel
@using LotteryVoteMVC.Models
@using LotteryVoteMVC.Resources
@using LotteryVoteMVC.Utility
@{
    ViewBag.Title = "Add";
}
@section Header{
    <script src="@Url.Content("~/Scripts/Customer/ajaxHelper.js")" type="text/javascript"></script>
    <style type="text/css">
        .content
        {
            overflow: hidden;
        }
        .content ul
        {
            float: left;
            width: auto;
            padding-right: 10px;
        }
        .content .panel
        {
            width: auto;
            float: left;
        }
        dd
        {
            overflow: hidden;
        }
        dd div
        {
            float: left;
        }
    </style>
    <script type="text/javascript">
        var onSuccess = function (data) {
            var result = eval(data);
            alert(data.Message);
        }
        var getActions = function (controller) {
            var url = "/ShadowAuthorize/GetActions/{0}?ticket={1}".format(controller, new Date().getTime());
            $.ajax({
                url: url,
                type: "GET",
                success: function (data) {
                    var result = eval(data);
                    if (result.IsSuccess) {
                        $("#Controller").val(controller);
                        var actionUl = $("#actions");
                        actionUl.children().remove();
                        $(result.Model.actions).each(function (i, obj) {
                            var li = $("<li action='{0}' sign='{1}'>{0}({1})</li>".format(obj.Key, obj.Value));
                            actionUl.append(li);
                            li.bind("click", function () {
                                $("#Action").val($(this).attr("action"));
                                $("#MethodSign").val($(this).attr("sign"));
                            });
                        });
                    }
                    else
                        alert(result.Message);
                },
                error: function (data) {
                    alert(data);
                }
            });
        }
    </script>
}
<div class="content">
    <ul>
        @foreach (var type in ViewBag.Controllers)
        { 
            <li><span onclick="getActions('@type.Name')">@type.Name</span></li>
        }
    </ul>
    <ul id="actions">
    </ul>
    <div class="panel">
        @using (Html.BeginForm())
        {
            <dl>
                <dt>Name:</dt>
                <dd>@Html.TextBoxFor(it => it.Name)
                    @Html.ValidationMessageFor(it => it.Name)
                </dd>
                <dt>Role:</dt>
                <dd>@Html.CheckBoxList("AuthRole", ViewBag.Roles as MultiSelectList)
                    @Html.ValidationMessageFor(it => it.AuthRole)
                </dd>
                <dt>Controller:</dt>
                <dd>@Html.TextBoxFor(it => it.Controller)
                    @Html.ValidationMessageFor(it => it.Controller)
                </dd>
                <dt>Action:</dt>
                <dd>@Html.TextBoxFor(it => it.Action)
                    @Html.ValidationMessageFor(it => it.Action)
                </dd>
                <dt>Action Sign:</dt>
                <dd>@Html.TextBoxFor(it => it.MethodSign)
                    @Html.ValidationMessageFor(it => it.MethodSign)
                </dd>
                <dt>Default State:</dt>
                <dd>
                    @Html.CheckBoxFor(it => it.DefaultState)
                    @Html.ValidationMessageFor(it => it.DefaultState)
                </dd>
            </dl>
            <input type="submit" name="submit" id="submit" value="提交" />
        }
    </div>
</div>
